<template>
  <a-list
    item-layout="horizontal"
    :data-source="data"
    style="max-height:250px;overflow-y: auto;"
  >
    <div
      v-if="showLoadingMore"
      slot="loadMore"
      :style="{ textAlign: 'center', marginTop: '12px', height: '32px', lineHeight: '32px' }"
    >
      <a-spin v-if="loadingMore" />
      <div v-if="!loadingMore && data.length>0">
        <a-button v-if="ipagination.pageNo < ipagination.pages" @click="onLoadMore" type="link">
          加载更多
        </a-button>
        <a-button v-else type="link">
          暂无更多
        </a-button>
      </div>
    </div>
    <a-list-item slot="renderItem" slot-scope="item, index">
      <a-list-item-meta
        :description="'修改字段'+getFile(item.fieldName).label+':'+getFileText(item) "
      >
        <a slot="title">{{item.createTime +'    '+ item.createBy_dictText }}</a>
        <a-avatar slot="avatar" icon="sound"/>
      </a-list-item-meta>
    </a-list-item>
  </a-list>
</template>
<script >
import { getAction } from '@/api/manage'
import { filterDictTextByCache } from '@/components/dict/JDictSelectUtil'
export default {
  name: 'Projectlog',
  data() {
    return {
      data: [],
      showLoadingMore: true,
      loadingMore: false,
      ipagination: {
        pageNo: 1,
        pageSize: 5,
        pages: 1
      },
      fileOption: [
        { label: '项目名称', value: 'projectName' },
        { label: '项目编码', value: 'projectCode' },
        { label: '时间', value: 'time' },
        { label: '项目类型', value: 'projectType', dictCode: 'pms_project_type' },
        { label: '项目经理', value: 'projectManager' },
        { label: '项目助理', value: 'projectAssistant' },
        { label: '成员', value: 'projectMember' },
        { label: '抄送人', value: 'ccMember' },
        { label: '归属部门', value: 'departCode' },
        { label: '项目状态', value: 'projectStatus', dictCode: 'pms_project_status' },
        { label: '项目描述', value: 'projectDesc' },
        { label: '项目附件', value: 'filePath' }
      ]
    }
  },
  props: ['projectCode', 'param'],
  mounted() {
    if (this.param && this.param.projectCode) {
      this.loadProjectlog()
    } else {
      this.data = []
    }
  },
  methods: {
    filterDictTextByCache,
    loadProjectlog() {
      var param = Object.assign(this.param, this.ipagination)
      getAction('/pms/projectlog/list', param).then(res => {
        if (res.success) {
          this.data = this.data.concat(res.result.records)
          this.ipagination.pages = res.result.pages
        }
      })
    },
    onLoadMore() {
      this.ipagination.pageNo++
      this.loadProjectlog()
    },
    getFile(value) {
      const file = this.fileOption.filter(item => item.value === value)
      return file.length ? file[0] : { label: value }
    },
    getFileText(file) {
      const option = this.getFile(file.fieldName)
      if (option.dictCode) {
        return filterDictTextByCache(option.dictCode, file.oldValue) + ' -> ' + filterDictTextByCache(option.dictCode, file.newValue)
      } else {
        return file.oldValue + ' -> ' + file.newValue
      }
    }
  }
}
</script>
<style lang='scss'>
</style>
